import type { DictRegionModel } from "@/api/region/os-dict-region/types";

export interface ExtractIdsOrCodes {
  regionIds: string[];
  regionCodes: string[];
}
/**
 * 返回区域ID和区域编码
 * @param model DictRegionModel
 * @returns ExtractIdsOrCodes { regionIds: string[], regionCodes: string[] }
 */
export const extractIdsOrCodes = (
  model: DictRegionModel
): ExtractIdsOrCodes => {
  const regions: ExtractIdsOrCodes = {
    regionIds: [],
    regionCodes: [],
  };

  const recurse = (model: DictRegionModel) => {
    regions.regionIds.push(model.regionId);
    regions.regionCodes.push(model.regionCode);

    if (model.children && model.children.length > 0) {
      model.children.forEach((child) => recurse(child));
    }
  };

  recurse(model);

  return regions;
};
